<template>
  <div class="video-gallery-container">
    <!-- 顶部标签栏（与插画界面一致） -->
    
    <!-- 视频网格列表 -->
    <div class="video-grid">
            <div
        v-for="(video, index) in videos"
        :key="video.id"
        class="video-card"
        @click="playVideo(video)"
        @mouseenter="setHoverIndex(index)"
        @mouseleave="hoverIndex = -1"
      >
        <!-- 视频缩略图 -->
        <div class="video-thumbnail">
          <img 
            :src="video.thumbnail" 
            :alt="video.title"
            class="thumbnail-image"
          />
          <div class="video-overlay" :class="{ active: hoverIndex === index }">
            <div class="play-button">
              <el-icon size="24"><VideoPlay /></el-icon>
            </div>
          </div>
          
        </div>
      </div>
        <!-- 图片网格列表 -->
         <div 
          v-for="(imags, index) in imags" 
          :key="imags.id" 
          class="image-card"
        >
          <div class="image-container">
            <el-image
              :src="imags.imageUrl"
              :alt="imags.title"
              class="equipment-image"
              fit="cover"
              :preview-src-list="previewList"
              :initial-index="index"
              hide-on-click-modal
            @click="openPreview66(imags.imageUrl)"
            >
              <template #error>
                <div class="image-slot">
                  <el-icon></el-icon>
                </div>
              </template>
            </el-image>
          </div>
        </div>

    </div>

    <!-- 视频播放模态框 -->
    <el-dialog
      v-model="showVideoPlayer"
      width="70%"
      :before-close="closeVideoPlayer"
    >
      <div class="video-player-wrapper">
        <video
          ref="videoPlayer"
          :src="currentVideo.videoUrl"
          controls
          autoplay
          class="video-player"
        >
          您的浏览器不支持视频播放
        </video>
        <div class="player-info">
          <h2>{{ currentVideo.title }}</h2>
          <p>{{ currentVideo.description }}</p>
        </div>
      </div>
    </el-dialog>
    <!-- 放大预览模态框 -->
    <el-dialog
      v-model="previewVisible"
      width="980px"
    >
      <div class="preview-container">
        <img :src="currentImage" 
          alt="图片预览"
          style="width: 940px;height: 700px;"
        class="preview-image" />
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { VideoPlay } from '@element-plus/icons-vue'
import { useCounterStore } from '@/stores/counter'
import axios from 'axios'
import { nextTick } from 'vue' // 必须显式导入


// 响应式数据
const userStore=useCounterStore()
const videos = ref([])
const hoverIndex = ref(-1)
const showVideoPlayer = ref(false)
const currentVideo = ref({})
const videoPlayer = ref(null)
const imags = ref([])
// 图片数据
const currentImage=ref('')
// 图片数据
const previewVisible = ref(false)

const equipmentId=userStore.equipmentId

//获取设备图片1
    const getEquipmentImage =async () => {
      const {data:response} = await axios.get(`/advertisement/equipmentImage/${equipmentId}/image`)
      console.log('image',response.data.list)
      imags.value = response.data.list
    }

//视频按钮
const sp =async () => {
  console.log('视频',equipmentId)
  const {data:response} = await axios.get(`/advertisement/equipmentVideo/${equipmentId}`)
  console.log('video',response.data.equipmentVideo)
  videos.value = response.data.equipmentVideo
  getEquipmentImage()
}
// 模拟视频数据（匹配插画风格）
const videoData = [
]

// 预览列表
const openPreview66 =(imags)=> {
 console.log('图片',imags)
 currentImage.value = imags
 console.log('图片',currentImage)
 //打开模态框
 previewVisible.value = true
}

// 初始化数据
onMounted(() => {
  sp()
})

// 设置悬停索引
const setHoverIndex = (index) => {
  hoverIndex.value = index
}

// 播放视频
const playVideo = (video) => {
  console.log('播放视频',video)
  currentVideo.value = video
  showVideoPlayer.value = true
  
  // 确保视频元素加载
  nextTick(() => {
    if (videoPlayer.value) {
      videoPlayer.value.load()
    }
  })
}

// 关闭视频播放器
const closeVideoPlayer = () => {
  showVideoPlayer.value = false
  if (videoPlayer.value) {
    videoPlayer.value.pause()
  }
}

// 格式化视频时长
const formatDuration = (seconds) => {
  const mins = Math.floor(seconds / 60)
  const secs = seconds % 60
  return `${mins}:${secs.toString().padStart(2, '0')}`
}
</script>

<style scoped>
.video-gallery-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background: #f8f9fa;
  
}

/* 标签栏样式（匹配插画界面） */
.tab-header {
  background: white;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 30px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.tab-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.tab-item {
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
}

.tab-item.active {
  background: #8b0000; /* 暗红色，匹配插画色调 */
  color: white;
}

.tab-count {
  color: #666;
  font-size: 14px;
}

/* 视频网格布局 */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

/* 视频卡片样式 */
.video-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.video-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(139, 0, 0, 0.15);
}

/* 缩略图容器 */
.video-thumbnail {
  position: relative;
  height: 202px;
  overflow: hidden;
}

.thumbnail-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.video-card:hover .thumbnail-image {
  transform: scale(1.05);
}

/* 视频悬停遮罩 */
.video-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(139, 0, 0, 0.7); /* 暗红色遮罩 */
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.video-overlay.active {
  opacity: 1;
}

.play-button {
  color: white;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

/* 视频时长标签 */
.video-duration {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* 视频信息区域 */
.video-info {
  padding: 16px;
}

.video-title {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 8px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-description {
  font-size: 14px;
  color: #666;
  line-height: 1.4;
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #999;
}

/* 视频播放器模态框 */
.video-player-wrapper {
  text-align: center;
}

.video-player {
  width: 100%;
  max-height: 500px;
  border-radius: 8px;
}

.player-info {
  padding: 20px;
  text-align: left;
}

.player-info h2 {
  color: #2c3e50;
  margin-bottom: 10px;
}

.player-info p {
  color: #666;
  line-height: 1.5;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
  }
  
  .tab-nav {
    flex-direction: column;
    gap: 10px;
  }
  
  .video-player {
    max-height: 300px;
  }
}

@media (max-width: 480px) {
  .video-grid {
    grid-template-columns: 1fr;
  }
  
  .video-gallery-container {
    padding: 10px;
  }
}
 * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    }
    body {
      background-color: #f5f7fa;
      padding: 20px;
    }
    .equipment-album {
      max-width: 1200px;
      margin: 0 auto;
      background: white;
      border-radius: 8px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      overflow: hidden;
    }
    .album-header {
      padding: 20px 24px;
      border-bottom: 1px solid #e8e8e8;
      background: #fafafa;
    }
    .album-title {
      font-size: 20px;
      font-weight: 600;
      color: #303133;
      display: flex;
      align-items: center;
    }
    .album-count {
      margin-left: 10px;
      font-size: 14px;
      color: #909399;
      font-weight: normal;
    }
    .album-content {
      padding: 20px;
    }
    .image-grid {
      margin-top: 20px;
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: 20px;
    }
    .image-card {
      border: 1px solid #e4e7ed;
      border-radius: 6px;
      overflow: hidden;
      transition: all 0.3s ease;
      background: white;
    }
    .image-card:hover {
      transform: translateY(-4px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
      border-color: #409eff;
    }
    .image-container {
      position: relative;
      width: 100%;
      height: 200px;
      overflow: hidden;
      cursor: pointer;
    }
    .equipment-image {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.3s ease;
    }
    .image-container:hover .equipment-image {
      transform: scale(1.05);
    }
    .image-info {
      padding: 12px 16px;
      border-top: 1px solid #f0f0f0;
    }
    .image-title {
      font-size: 14px;
      font-weight: 600;
      color: #303133;
      margin-bottom: 4px;
    }
    .image-desc {
      font-size: 12px;
      color: #909399;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .image-category {
      background: #ecf5ff;
      color: #409eff;
      padding: 2px 6px;
      border-radius: 3px;
      font-size: 11px;
    }
    .empty-state {
      text-align: center;
      padding: 60px 20px;
      color: #909399;
    }
    .empty-icon {
      font-size: 48px;
      margin-bottom: 16px;
      color: #c0c4cc;
    }
    .filter-tabs {
      margin-bottom: 20px;
      border-bottom: 1px solid #e4e7ed;
    }
    .view-mode {
      display: flex;
      justify-content: flex-end;
      margin-bottom: 20px;
    }
    @media (max-width: 768px) {
      .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 15px;
      }
      .album-content {
        padding: 15px;
      }
    }
    @media (max-width: 480px) {
      .image-grid {
        grid-template-columns: 1fr;
      }
    }
</style>